﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;

namespace ISO
{
    class Character
    {
        #region Variables
        private double _x_index;
        private double _y_index;
        private double _x_offset;
        private double _y_offset;
        private int _hit_points;
        public enum States
        {Attacking, Idle, Moving, Dead};
        private States _state;
        private bool _friendly;
        private int _attack;
        private Texture2D _texture;
        #endregion

        #region Attributes
        public double X_Offset
        {
            get { return _x_offset; }
            set { _x_offset = value; }
        }
        public double Y_Offset
        {
            get { return _y_offset; }
            set { _y_offset = value; }
        }
        public double X_Index
        {
            get { return _x_index; }
            set { _x_index = value; }
        }
        public double Y_Index
        {
            get { return _y_index; }
            set { _y_index = value; }
        }
        public int Hit_Points
        {
            get { return _hit_points; }
            set { _hit_points = value; }
        }
        public States State
        {
            get { return _state; }
            set { _state = value; }
        }
        public bool Friendly
        {
            get { return _friendly; }
            set { _friendly = value; }
        }
        public int Attack
        {
            get { return _attack; }
            set { _attack = value; }
        }
        public Texture2D Texture
        {
            get { return _texture; }
            set { _texture = value; }
        }
      #endregion

        #region Constructors
        public Character(int _starting_x_index, int _starting_y_index, Texture2D _texture, int hp, int atk)
        {
            this._texture = _texture;
            _x_index = _starting_x_index;
            _y_index = _starting_y_index;
            _x_offset = 0;
            _y_offset = 0;
        }
        #endregion

        #region Methods
        public void Deal_Damage(Character target){
            if (In_Range(target))
            {
                target.Take_Damage(this.Attack);
            }
        }

        public void Take_Damage(int dam){
           _hit_points -= dam;
           if (_hit_points <= 0)
           {
               _state = States.Dead;
           }
        }

        public bool In_Range(Character target)
        {
            if ((this.X_Index == target.X_Index - 1 && this.Y_Index == target.Y_Index) ||
                (this.X_Index == target.X_Index + 1 && this.Y_Index == target.Y_Index) ||
                (this.X_Index == target.X_Index && this.Y_Index == target.Y_Index - 1) ||
                (this.X_Index == target.X_Index && this.Y_Index == target.Y_Index + 1))
                return true;
            else return false;
        }
        #endregion
    }
}
